/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD;

import csse3004.GD.DA.LoginDA;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.ServletException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class LoginController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log m_logger = LogFactory.getLog(getClass());
    private LoginService loginService = new LoginDA();
    
    @Override
    public ModelAndView onSubmit(Object command) throws ServletException {
        
        Account loggy = (Account) command;
        String username = loggy.getUsername();
        String password = loggy.getPassword();
        
        m_logger.info("I've Got: "+username+" for Username");
        m_logger.info("I've Got: "+password+" for Password");
        
        int userID = loginService.getUserID(username);
        String type = loginService.getUserType(username);
        
        ModelAndView mnv = new ModelAndView(new RedirectView(getSuccessView()));
        mnv.addObject("login", loggy.getUsername());
        mnv.addObject("userID", userID);
        mnv.addObject("userType", type);
        
        return mnv;
        //return new ModelAndView(new RedirectView(getSuccessView()), "login", loggy.getUsername());
    }

}